package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.domain.Salary;
import cn.wolfcode.crm.mapper.SalaryMapper;
import cn.wolfcode.crm.query.SalaryQueryObject;
import cn.wolfcode.crm.service.ISalaryService;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SalaryServiceImpl implements ISalaryService {

    @Autowired
    private SalaryMapper mapper;


    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    public void save(Salary entity) {
        mapper.insert(entity);
    }

    public Salary get(Long id) {
        //获取当前登录用户的id
        Employee employee = (Employee) SecurityUtils.getSubject().getPrincipal();
        return mapper.getById(employee.getId());
    }

    public List<?> list() {
        return mapper.selectAll();
    }

    public PageResult query(SalaryQueryObject qo) {
        int total = mapper.queryForCount(qo);
        if (total == 0) {
            return new PageResult();
        }
        List<Salary> list = mapper.queryForList(qo);
        return new PageResult(total,list);
    }
}
